From 3c59734da2cf0d963481802f0107222fcf3fa8f5 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Tue, 20 May 2025 23:35:29 +0200 Subject: [PATCH] =?utf8?q?fix(readonly):=20ignore=20move=20to=20trash=20fo?= =?utf8?q?r=20read-=C3=A8only=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Matthieu Gallien --- src/libsync/propagatorjobs.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp index 272fe40b6..ca0919b5f 100644 --- a/src/libsync/propagatorjobs.cpp +++ b/src/libsync/propagatorjobs.cpp @@ -107,8 +107,35 @@ void PropagateLocalRemove::start() } QString removeError; - if (_moveToTrash && propagator()->syncOptions()._vfs->mode() != OCC::Vfs::WindowsCfApi) { - const auto fileInfo = QFileInfo{filename}; + auto moveToTrashIsFeasible = true; + if (propagator()->syncOptions()._vfs->mode() != OCC::Vfs::WindowsCfApi) { + moveToTrashIsFeasible = false; + } + const auto fileInfo = QFileInfo{filename}; + if (fileInfo.isDir()) { + try { + if (FileSystem::isFolderReadOnly(fileInfo.filesystemAbsolutePath())) { + moveToTrashIsFeasible = false; + } + } + catch (const std::filesystem::filesystem_error &e) + { + qCWarning(lcPropagateLocalRemove) << "exception when checking parent folder read only status" << e.what() << e.path1().c_str() << e.path2().c_str(); + } + catch (const std::system_error &e) + { + qCWarning(lcPropagateLocalRemove) << "exception when checking parent folder read only status" << e.what(); + } + catch (...) + { + qCWarning(lcPropagateLocalRemove) << "exception when checking parent folder read only status"; + } + } else { + if (!FileSystem::isWritable(filename, fileInfo)) { + moveToTrashIsFeasible = false; + } + } + if (_moveToTrash && moveToTrashIsFeasible) { if (FileSystem::fileExists(filename, fileInfo)) { const auto parentFolderPath = fileInfo.dir().absolutePath(); const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite}; @@ -123,12 +150,11 @@ void PropagateLocalRemove::start() } } else { if (_item->isDirectory()) { - if (FileSystem::fileExists(filename) && !removeRecursively(QString())) { + if (FileSystem::fileExists(filename, fileInfo) && !removeRecursively(QString())) { done(SyncFileItem::NormalError, tr("Temporary error when removing local item removed from server."), ErrorCategory::GenericError); return; } } else { - const auto fileInfo = QFileInfo{filename}; if (FileSystem::fileExists(filename, fileInfo)) { const auto parentFolderPath = fileInfo.dir().absolutePath(); const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite}; -- 2.30.2